import {
    removeBtnHandler
} from './remove';
import {
    grid
} from '../common/grid';
import {
    editPwd,loginOut
} from '../common/settings';

$(function () {

    grid();
    window.editPwd=editPwd;
    window.loginOut=loginOut;

    let $table = $('#table').bootstrapTable({
        toolbar: '#toolbar',
        url: GLOBAL_jobListUrl,
        sidePagination: "server",
        queryParamsType: '',
        sortName: '',
        columns: [{
            checkbox: true
        }, {
            field: 'name',
            title: '姓名',
            sortable: true
        }, {
            field: 'phone',
            title: '手机号',
            sortable: true
        }, {
            field: 'mail',
            title: '邮箱',
            sortable: true
        }, {
            field: 'content',
            title: '留言',
            sortable: true,
            formatter: function (value, row, index) {
                return `<div class="tips" data-toggle="tooltip" title="${value}">查看</div>`;
            },
        }, {
            field: 'time',
            title: '添加时间',
            formatter: function (value, row, index) {
                var time = moment(value * 1000).format('YYYY-MM-DD');
                return time;
            },
            sortable: true
        }]
    });



    window.removeBtnHandler = removeBtnHandler;

    //多选不能编辑
    $table.on('check.bs.table', () => {
        let selectedList = $('#table').bootstrapTable('getSelections');
        if (selectedList.length > 1) {
            $('#editBtn').attr('disabled', 'disabled');
            return;
        }
        $('#editBtn').removeAttr('disabled');
    });
    $table.on('uncheck.bs.table', () => {
        let selectedList = $('#table').bootstrapTable('getSelections');
        if (selectedList.length > 1) {
            $('#editBtn').attr('disabled', 'disabled');
            return;
        }
        $('#editBtn').removeAttr('disabled');
    });
    $table.on('check-all.bs.table', (rows) => {
        $('#editBtn').attr('disabled', 'disabled');
    });
    $table.on('uncheck-all.bs.table', (rows) => {
        $('#editBtn').removeAttr('disabled');
    });



});